package com.hznu.coursemanagerbackend.modules.sys.service.impl;

import com.hznu.coursemanagerbackend.modules.sys.entity.User;
import com.hznu.coursemanagerbackend.modules.sys.dao.UserDao;
import com.hznu.coursemanagerbackend.modules.sys.service.UserService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.hznu.coursemanagerbackend.modules.sys.service.base.PasswordHelper;
import com.hznu.coursemanagerbackend.myBeans.ConfigParameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author DragonDoor
 * @since 2018-11-12
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserDao, User> implements UserService {

    @Autowired
    private PasswordHelper passwordHelper;

    @Autowired
    private ConfigParameters configParameters;

    @Override
    public void add(User user)
    {
        if(user.getPassword()!=null)
        {
            user.setPassword(configParameters.getDefaultPassword());
        }
        passwordHelper.encryptPassword(user); // 加密密码
        this.insert(user);
    }

}
